<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intAct			= $objRequest->getParam('act',0);
$intParentId	= $objRequest->getParam('parentid',0);
$intValue		= $objRequest->getParam('val',0);
$intType		= $objRequest->getParam('type',0);
$strId			= $objRequest->getParam('id','');
$intError		= 0;
$strMessage		= '';
$intLike		= 0;
if($intAct) {
	switch($intAct) {
		case 1:
			if($intType == 1) {
				$objBlog = new Blog();
				$intError = $objBlog->addLike($AppUI->id, $intValue, $intLike);		
				if($intError > 0) {
					$intError += 43;
				} else $strMessage = $arrMessage[1];
			}elseif($intType == 2) {
				$objPhoto 	= new Photo();
				$intError	= $objPhoto->addLike($AppUI->id,$intValue,$intLike);
				if($intError > 0) {
					$intError += 49;
				} else $strMessage = $arrMessage[7];
			}elseif($intType == 3) {
				$objFullhouse 	= new Fullhouse();
				$intError 	= $objFullhouse->addLike($AppUI->id, $intValue, $intLike);		
				if($intError > 0) $intError += 46;
				else $strMessage = $arrMessage[16];				
			}elseif($intType == 4) {
				
			}elseif($intType == 5) {
				$objNews 	= new News();
				$intError 	= $objNews->addLike($AppUI->id, $intValue, $intLike);	
				if($intError > 0) $intError += 17;
				else $strMessage = $arrMessage[11];
			}elseif($intType == 6) {
				$objPlace	= new Place();
				$intError 	= $objPlace->addLike($AppUI->id, $intValue, $intLike);
				if($intError > 0) $intError = 65;
				else $strMessage = $arrMessage[24];
			}
			break;
		case 2:
			if($intType == 1) {
				$objBlog 	= new Blog();
				$intError 	= $objBlog->addLikeCmt($AppUI->id, $intParentId, $intValue, $intLike);
			}elseif($intType == 2) {
				$objPhoto 	= new Photo();
				$intError 	= $objPhoto->addLikeCmt($AppUI->id, $intParentId, $intValue, $intLike);						
			}elseif($intType == 3) {
				$objFullhouse 	= new Fullhouse();
				$intError 	= $objFullhouse->likeCmt($AppUI->id, $intParentId, $intValue, $intLike);						
			}elseif($intType == 4) {
				$objOffline = new Offline();
				$intError 	= $objOffline->addLikeCmt($AppUI->id, $intParentId, $intValue, $intLike);
			}elseif($intType == 5) {
				$objNews	= new News();
				$intError 	= $objNews->addLikeCmt($AppUI->id, $intParentId, $intValue, $intLike);						
			}
			if($intError > 0) {
				if($intType != 5)
					$intError += 40;					
				else
					$intError += 52;
			}else {
				if($intType != 5)
					$strMessage = $arrMessage[15];	
				else
					$strMessage = $arrMessage[21];	
			}
			break;
		case 3:
			$objBehaviour	= new Behaviour();
			$objBehaviour->updateShTopic($AppUI->id, $strId, 0);
			$arrBehaviour	= $objBehaviour->get($strId);
			$this->view->item	= $arrBehaviour;
			$this->view->ajax	= 1;
			$objView	= Zend_Registry::get('objView');
			$strData	= $objView->fetch('index/box-behaviour-item.tpl');
			$arrJson 	= array('error'=>$intError,'msg'=>$arrMessage[17],'data'=>$strData);	
			break;
		case 5:
			$intPerm		= $objRequest->getParam('perm',0);
			$intStype		= $objRequest->getParam('stype',0);
			$intOwnerId		= 0;
			$objPhoto		= new Photo();
			$objURequest	= new URequest();			
			if($intPerm < 3) {
				$intPerm   += 2; 
				$intReport	= $intPerm + 4;				
				$arrResult	= $objPhoto->updateAlbumPerm($intValue, $intPerm, $intOwnerId);
				$objURequest->addReport($AppUI->id, $arrReport[1], '', $intReport, $intValue, $intOwnerId);
				$strMessage	= $arrMessage[19];
			} else {
				$intPerm   += 2; 				
				$arrResult	= $objPhoto->updateAlbumPerm($intValue, $intPerm, $intOwnerId);
				$objURequest->addReport($AppUI->id, $arrReport[1], '', 2, $intValue, $intOwnerId);
				$strMessage	= $arrMessage[20];
			}			
			$objBehaviour	= new Behaviour();
			$objBehaviour->updateShTopicByReport($intType,$intStype,$intValue,3);
			$arrJson 	= array('error'=>$intError, 'msg'=>$strMessage);	
			break;
		case 6:
			$objBehaviour 	= new Behaviour();
			$objBehaviour->updateReadById($AppUI->id, $strId);
			$arrBehaviour	= $objBehaviour->get($strId);
			$this->view->item		= $arrBehaviour;
			$this->view->type		= $intType;
			$this->view->arrDefault	= $arrDefault;
			$this->view->ajax 		= 1;
			$objView	= Zend_Registry::get('objView');			
			$strSub		= $objView->fetch('index/box-behaviour-sub.tpl');
			$arrJson	= array('error'	=> $intError, 	
								'dsub'	=> $strSub);
			break;
		case 7:
			include_once('index/box-behaviour.php');
			$this->view->ajax 	= 1;
			$objView			= Zend_Registry::get('objView');			
			$strBehaviour		= $objView->fetch('index/box-behaviour.tpl');
			$arrJson	= array('error'		=> $intError, 	
								'dbehaviour'=> $strBehaviour);
			break;
		case 8:
			$objNews	= new News();
			$intError	= $objNews->plusLnews($AppUI->id, $intValue, $intLike);
			if($intError == 0) {
				$strMessage = $arrMessage[22];		
			} else {
				$intError += 57;
			}			
			break;
	}
	if($intError == 0 && ( $intAct < 3 || 7 < $intAct)) {				
		$objBehaviour 	= new Behaviour();
		$objBehaviour->updateShTopic($AppUI->id, $strId, 1);
		$arrBehaviour	= $objBehaviour->get($strId);
		$this->view->item	= $arrBehaviour;
		$this->view->type	= $intType;
		$this->view->ajax 	= 1;
		$objView	= Zend_Registry::get('objView');
		$strInfo	= $objView->fetch('index/box-behaviour-info.tpl');	
		$arrJson 	= array('error'=>$intError,'msg'=>$strMessage,'dinfo'=>$strInfo,'like'=>Vfriend_Function::numberFormat($intLike));	
	}	
}
if($intError > 0) {
	$strError	= $arrError[$intError];
	$arrJson 	= array('error'=>$intError,'msg'=>$strError);	
}
echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
exit();
?>
